package com.dman.multi.cmd;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public class CommandInvoker {
	private Map<String, Command> strCommand = null;
	
	public CommandInvoker(Map<String, Command> strCommand) {
		this.strCommand = new HashMap<String, Command>();
		if(strCommand != null)
			this.strCommand.putAll(strCommand);
	}
	
	public void invoke(String cmdName) throws InvocationTargetException{
		Command command = strCommand.get(cmdName);
		if(command == null)
			throw new InvocationTargetException(new NullPointerException("Command is null"));
		command.execute();
	}
	
	public void add(String cmdName, Command cmd){
		strCommand.put(cmdName, cmd);
	}
	
	public void remove(String cmdName){
		strCommand.remove(cmdName);
	}
}
